class PoemListScene extends eui.Component {
    private stageW: number;
    private stageH: number;
    private poemList: Array<Poem>;
    private poemListCom: eui.List;

    public constructor() {
        super();
        this.skinName = "PoemListSceneSkin";
        this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
    }

    private addToStage() {
        const {ctx} = Director.getInstance();
        this.stageW = this.stage.stageWidth;
        this.stageH = this.stage.stageHeight;
        this.poemList = ctx['poemList'];
        this.buildList(1);

        const winSkeJson = RES.getRes("win_ske_json");
        const winTexJson = RES.getRes("win_tex_json");
        const winTexPng = RES.getRes("win_tex_png");
        const egretFactory: dragonBones.EgretFactory = dragonBones.EgretFactory.factory;
        egretFactory.parseDragonBonesData(winSkeJson);
        egretFactory.parseTextureAtlasData(winTexJson, winTexPng);
        const armatureDisplay: dragonBones.EgretArmatureDisplay = egretFactory.buildArmatureDisplay("girl-win");
        this.addChild(armatureDisplay);
        armatureDisplay.x = 200;
        armatureDisplay.y = 300;
        armatureDisplay.scaleX = 0.5;
        armatureDisplay.scaleY = 0.5;
        armatureDisplay.animation.play("girl-win");

        drawBackBtn(this, Dispatcher.showMain);
    }

    private buildList(page: number) {
        const {stageW, stageH, poemList} = this;
        const scrollerPw = 2 * SizePw;
        const liW = stageW - 2 * scrollerPw;
        const bottomH = 60;
        const fromY = 100;

        const bg = new egret.Shape();
        bg.graphics.beginFill(ColorYunShuiLan, 1);
        bg.graphics.drawRect(0, 0, stageW, stageH);
        bg.graphics.endFill();
        this.addChild(bg);

        const poemListCom = new eui.List();
        poemListCom.itemRendererSkinName = 'resource/eui_skins/PoemListItemSkin.exml';
        poemListCom.dataProvider = new eui.ArrayCollection(poemList);

        const scrollerH = stageH - fromY - bottomH;
        const scrollerBg = new egret.Shape();
        scrollerBg.graphics.beginFill(ColorWhite, 1);
        scrollerBg.graphics.drawRoundRect(scrollerPw - 10, fromY - 10, liW + 20, scrollerH + 20, 50, 50);
        scrollerBg.graphics.endFill();
        this.addChild(scrollerBg);

        const scroller = new eui.Scroller();
        this.poemListCom = poemListCom;
        poemListCom.selectedIndex = 1;//设置默认选中项
        poemListCom.addEventListener(eui.ItemTapEvent.ITEM_TAP, (evt: eui.PropertyEvent): void => {
            const n = evt['itemIndex'];
            Dispatcher.showPoem(n);
        }, this);

        scroller.viewport = poemListCom;
        scroller.height = scrollerH;
        scroller.width = liW;
        scroller.x = scrollerPw;
        scroller.y = fromY;
        this.addChild(scroller);
    }
}
